<template>
  <div>
    <el-carousel
      :interval="3000"
      type="card"
      :autoplay="true"
      :loop="true"
      class="swiper"
      height="300px"
    >
      <el-carousel-item v-for="(banner, index) in bannerList" :key="banner.id" :style="`background:${banner.color};`">
        <!-- <h3 class="medium">{{ item }}</h3> -->
        <div class="swiperContent">
          <!-- 字 -->
          <div class="text">
            <h2 class="swName">{{ banner.name }}</h2>
            <h1 class="swg">{{ banner.guanggao }}</h1>
            <h4 class="swS">{{ banner.shangpin ? banner.shangpin : "" }}</h4>
          </div>
          <!-- 图 -->
          <img :src="banner.imgUrl" />
        </div>
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script>
import { reqBannerList } from "@/api/index";

export default {
  name: "HomeSwiper",
  data() {
    return {
      bannerList: [],
    };
  },
  beforeMount() {
    this.getSwiperList();
  },
  methods: {
    // 获取轮播图数据
    async getSwiperList() {
      const result = await reqBannerList();
      this.bannerList = result.data;
      console.log(result);
    },
  },
};
</script>

<style lang="less" scoped>
.el-carousel__item {
  margin: 5px 0;
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}
.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
.el-carousel__item .swiperContent {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.el-carousel__item img {
  height: 300px;
  width: 400px;
}
.el-carousel__item .text {
  margin: 0 auto;
}
.el-carousel__item .swg {
  padding: 60px 0;
  font-size: 30px;
}
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
.el-carousel__item .swiperContent {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.el-carousel__item img {
  height: 300px;
  width: 400px;
}
.el-carousel__item .text {
  margin: 0 auto;
}
.el-carousel__item .swg {
  padding: 60px 0;
  font-size: 30px;
}
</style>
